use axum::Json;
use http::HeaderMap;
use serde_json::Value;
use sea_orm::EntityTrait;

use crate::{code, query};

const NAME:&str = "audit";
// 禁用一个
pub async fn by_id<E:EntityTrait>( header:HeaderMap, entity:E, body:&Value ) -> Result<Json<Value>, Json<Value>>{
    let audit = query::bool(body, "audit")?;
    if audit == true {
        super::is_true::by_id(header, entity, body, NAME).await
    }else if audit == false {
        super::is_false::by_id(header, entity, body, NAME).await
    }else{
        code::sys("参数不正确")
    }
}
pub async fn  by_ids<E:EntityTrait>( header:HeaderMap, entity:E, body:&Value ) -> Result<Json<Value>, Json<Value>>{
    let audit = query::bool(body, "audit")?;
    if audit == true {
        super::is_true::by_ids(header, entity, body, NAME).await
    }else if audit == false {
        super::is_false::by_ids(header, entity, body, NAME).await
    }else{
        code::sys("参数不正确")
    }
}
pub async fn  by_id_auto<E:EntityTrait>( header:HeaderMap, entity:E, body:&Value ) -> Result<Json<Value>, Json<Value>>{
    let audit = query::bool(body, "audit")?;
    if audit == true {
        super::is_true::by_id_auto(header, entity, body, NAME).await
    }else if audit == false {
        super::is_false::by_id_auto(header, entity, body, NAME).await
    }else{
        code::sys("参数不正确")
    }
}
pub async fn  by_ids_auto<E:EntityTrait>( header:HeaderMap, entity:E, body:&Value ) -> Result<Json<Value>, Json<Value>>{
    let audit = query::bool(body, "audit")?;
    if audit == true {
        super::is_true::by_ids(header, entity, body, NAME).await
    }else if audit == false {
        super::is_false::by_ids(header, entity, body, NAME).await
    }else{
        code::sys("参数不正确")
    }
}